#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

void Test1()
{

	
}
int n;
int dp[100] = { 0 };

int mai1n() {

    cin >> n;
    dp[1] = 1;
    dp[2] = 2;

    if (n == 1 || n == 2) { cout << dp[n] << endl; return 0; }

    for (int i = 3; i <= n; i++)
    {
        dp[i] = dp[i - 1] * 2;
    }

    cout << dp[n];
    return 0;
}

int main2() {

    string str; cin >> str;

    int left, right, n = 1;
    int _max = 0;

    char c1 = str[0], c2;

    int count = 1;
    for (left = 0, right = 1; right < str.size(); )
    {
        if (n == 1 && str[right] != c1)
        {
            n++;
            c2 = str[right];
            left = right;
            count++;
            right++;
        }
        else if (str[right] == c1 || str[right] == c2)
        {
            if (str[right] == c2) { left = right; }
            count++;
            right++;
        }
        else
        {
            c1 = str[left];
            n = 1;
            _max = max(_max, count);
            count = 1;
            right = left + 1;
        }
    }

    _max = max(_max, count);

    cout << _max << endl;
    return 0;
}

int main() {

    string str; cin >> str;

    int left, right, n = 1;
    int _max = 0;

    char c1 = str[0], c2;

    int count = 1;
    for (left = 0, right = 1; right < str.size(); )
    {
        if (n == 1 && str[right] != c1)
        {
            n++;
            c2 = str[right];
            left = right;
            count++;
            right++;
        }
        else if (str[right] == c1 || str[right] == c2)
        {
            // if (str[right] == c2) { left = right; }
            count++;
            right++;
        }
        else
        {
            c1 = str[left];
            n = 1;
            _max = max(_max, count);
            count = 1;
            right = left + 1;
        }
    }

    _max = max(_max, count);

    cout << _max << endl;
    return 0;
}



int main() {
    string str, str2 = "[";
    cin >> str;

    sort(str.begin(), str.end());
    do {
        if (str2 == "[") {
            str2 += str;
        }
        else {
            str2 += ", " + str;
        }

    } while (next_permutation(str.begin(), str.end()));

    str2 += ']';

    cout << str2 << endl;
}

int main() {

    string str; cin >> str;

    int left, right, n = 1, l2;
    int _max = 0;

    char c1 = str[0], c2;

    int count = 1;
    for (left = 0, right = 1; right < str.size(); ++right)
    {
        if (n == 1 && str[right] != c1)
        {
            n++;
            c2 = str[right];
            left = right;
            count++;
        }
        else if (str[right] == c1 || str[right] == c2)
        {
            if (str[right] == c2) { l2 = right; }
            if (str[right] == c1 && l2 > left)
            {
                left = l2;
            }

            count++;
        }
        else
        {
            c1 = str[left];
            n = 1;
            _max = max(_max, count);
            count = 1;
            right = left;
        }
    }

    _max = max(_max, count);

    cout << _max << endl;
    return 0;
}